<template>
  <view class="transport flexc">
    <view class="header">
      <u-tabs
        :current="tabCurrent"
        :scrollable="true"
        :list="tabList"
        keyName="title"
        lineColor="#CB0011"
        :lineWidth="28"
        :lineHeight="2"
        @click="tabClick"
        :itemStyle="{
          height: '88rpx',
          fontSize: '28rpx',
          color: '#9695A3',
        }"
        :activeStyle="{ fontWeight: 'bold', color: '#000000' }"
        :inactiveStyle="{}"></u-tabs>
    </view>
    <!-- 中间数据展示 发起提交-->
    <template v-if="tabCurrent == 0 || tabCurrent == 2">
      <!-- 二级tab -->
      <view class="nav flex-center">
        <view :class="navIndex == 1 ? 'nav-ac' : ''" @click="navBtn(1)">
          抓鸭生产计划表
        </view>
        <view :class="navIndex == 2 ? 'nav-ac' : ''" @click="navBtn(2)">
          抓鸭运输数据记录表
        </view>
      </view>
      <template v-if="tabCurrent == 0">
        <view class="flex1 over" style="padding-bottom: 50upx">
          <template v-if="navIndex == 2">
            <view class="wrap mb16">
              <view class="box flexc">
                <view class="">序号</view>
                <input
                  class="flex1"
                  type="text"
                  v-model="form1.catch_duck_transportation_no"
                  placeholder="请输入 不输入自动生成" />
              </view>
              <view class="box flexc" @click="showDateBtn(1)">
                <view class="">
                  <text class="sc">*</text>
                  抓鸭日期
                </view>
                <view class="box-b flex">
                  <input
                    class="flex1"
                    type="text"
                    disabled
                    v-model="form1.catch_duck_date"
                    placeholder="默认选择当天" />
                  <image
                    src="/static/login/pop-arrow.png"
                    mode="aspectFit"></image>
                </view>
              </view>
              <view class="box flexc" @click="goyzh">
                <view class="">
                  <text class="sc">*</text>
                  养殖户
                </view>
                <view class="flex box-b">
                  <input
                    class="flex1"
                    type="text"
                    disabled
                    v-model="form1.farmer_title"
                    placeholder="请选择" />
                  <image
                    src="/static/login/pop-arrow.png"
                    mode="aspectFit"></image>
                </view>
              </view>
              <view class="box flexc">
                <view class="">地址</view>
                <input
                  class="flex1"
                  type="text"
                  disabled
                  v-model="form1.address"
                  placeholder="请选择" />
              </view>
              <view class="box flexc" @click="showPop(1)">
                <view class="">
                  <text class="sc">*</text>
                  车牌号
                </view>
                <view class="box-b flex">
                  <input
                    class="flex1"
                    type="text"
                    disabled
                    v-model="form1.plate_number"
                    placeholder="请选择" />
                  <image
                    src="/static/login/pop-arrow.png"
                    mode="aspectFit"></image>
                </view>
              </view>
              <view class="box flexc">
                <view class="">队长姓名</view>
                <input
                  class="flex1"
                  v-model="form1.captain_name"
                  type="text"
                  placeholder="请输入" />
              </view>
              <view class="box flexc" @click="showTimeBtn(0)">
                <view class="">到达基地时间</view>
                <view class="flex box-b">
                  <input
                    class="flex1"
                    type="text"
                    disabled
                    v-model="form1.arrive_base_time"
                    placeholder="请选择" />
                  <image
                    src="/static/login/pop-arrow.png"
                    mode="aspectFit"></image>
                </view>
              </view>
              <view class="box flexc" @click="showTimeBtn(1)">
                <view class="">到达工厂时间</view>
                <view class="flex box-b">
                  <input
                    class="flex1"
                    type="text"
                    disabled
                    v-model="form1.arrive_factory_time"
                    placeholder="请选择" />
                  <image
                    src="/static/login/pop-arrow.png"
                    mode="aspectFit"></image>
                </view>
              </view>
              <view class="box flexc" @click="showSku(0)">
                <view class="flex-between">
                  <view class="">
                    <text class="sc">*</text>
                    生产排序
                  </view>
                  <view class="">1-100</view>
                </view>
                <view class="flex box-b">
                  <input
                    class="flex1"
                    type="text"
                    disabled
                    v-model="form1.production_order"
                    placeholder="请选择" />
                  <image
                    src="/static/login/pop-arrow.png"
                    mode="aspectFit"></image>
                </view>
              </view>
              <view class="box flexc" @click="showSku(1)">
                <view class="flex-between">
                  <view class="">鸭规格</view>
                  <view class="">大，中，小</view>
                </view>
                <view class="flex box-b">
                  <input
                    class="flex1"
                    type="text"
                    disabled
                    v-model="form1.specifications"
                    placeholder="请选择" />
                  <image
                    src="/static/login/pop-arrow.png"
                    mode="aspectFit"></image>
                </view>
              </view>
            </view>
          </template>
          <template v-if="navIndex == 1">
            <view class="wrap mb16">
              <view class="box flexc" @click="showDateBtn(0)">
                <view class="">
                  <text class="sc">*</text>
                  计划生产日期
                </view>
                <view class="box-b flex">
                  <input
                    class="flex1"
                    type="text"
                    disabled
                    v-model="plan_date"
                    placeholder="默认选择当天" />
                  <image
                    src="/static/login/pop-arrow.png"
                    mode="aspectFit"></image>
                </view>
              </view>
              <view class="" v-for="(item, index) in list" :key="index">
                <view class="tip flex-between">
                  <view class="">录入明细{{ index + 1 }}</view>
                  <view
                    class="del"
                    v-if="!item.disabled"
                    @click="() => list.splice(index, 1)">
                    删除
                  </view>
                </view>
                <view class="box flexc">
                  <view class="">序号</view>
                  <input
                    class="flex1"
                    type="text"
                    v-model="item.catch_duck_no"
                    placeholder="请输入 不输入自动生成" />
                </view>

                <view class="box flexc">
                  <view class="">
                    <text class="sc">*</text>
                    只数
                  </view>
                  <input
                    class="flex1"
                    type="text"
                    v-model="item.num"
                    placeholder="请输入" />
                </view>
                <view class="box flexc">
                  <view class="">规格</view>
                  <input
                    class="flex1"
                    type="text"
                    v-model="item.specifications"
                    placeholder="请输入" />
                </view>
                <view class="box flexc">
                  <view class="">计划车次</view>
                  <input
                    class="flex1"
                    type="text"
                    v-model="item.planned_train_number"
                    placeholder="请输入" />
                </view>
                <view
                  class="flex-center add-icon"
                  v-if="index == list.length - 1"
                  @click="addList(0)">
                  <image src="/static/order/add.png" mode="aspectFit"></image>
                </view>
              </view>
            </view>
          </template>
          <view class="wrap mb16">
            <view class="box flexc">
              <view class="">备注</view>
              <u--textarea
                v-model="mark"
                height="200"
                border="none"
                maxlength="200"
                placeholder="请输入备注信息"
                count></u--textarea>
            </view>
          </view>
          <record_status_userVue
            :formType="navIndex + 2"
            :num="navIndex == 1 ? '2' : '1'" />
        </view>
        <view class="footer flex-between">
          <view class="box-icon column-flex-center" @click="submitBtn(0)">
            <image src="/static/order/5.png" mode="aspectFit"></image>
            <view class="">存草稿</view>
          </view>
          <view class="btn" @click="submitBtn(1)">提交</view>
        </view>
      </template>
      <!-- 养殖记录 -->
      <template v-if="tabCurrent == 2">
        <view class="search flex">
          <image src="/static/order/search.png" mode="aspectFit"></image>
          <input
            type="text"
            v-model="keyword"
            class="flex1"
            placeholder="搜索"
            @confirm="searchBtn" />
        </view>
        <view class="flex1 over" style="padding-bottom: 50upx">
          <scroll-view
            scroll-y="true"
            style="height: 100%"
            @scrolltolower="loadingMore">
            <view class="content-wrap">
              <view
                class="content-box"
                v-for="(item, index) in scrollList"
                :key="index"
                @click="goDetail(item)">
                <view class="flex-between">
                  <view class="flex">
                    <view :class="['t', item.status == 9 ? 'ac4' : '']">
                      {{ item.title }}
                    </view>
                    <view class="edit-text" v-if="item.pid > 0">修改</view>
                  </view>
                  <view class="t1">
                    {{ item.created_at }}
                  </view>
                </view>
                <view class="no flex-between">
                  <view class="">
                    序号：{{
                      item.catch_duck_no || item.catch_duck_transportation_no
                    }}
                  </view>
                  <view
                    class="cred"
                    v-if="item.pid > 0"
                    @click.stop="historyBtn(item)">
                    历史数据
                  </view>
                </view>
                <view class="t2 mb12">
                  服务日期：：{{ item.plan_date || item.catch_duck_date }}
                </view>
                <view class="t2" v-if="item.farmer_title">
                  养殖户：{{ item.farmer_title }}
                </view>
                <view class="flex-between mt34">
                  <view class="flex">
                    <image
                      class="img"
                      v-if="item.status != 9"
                      src="/static/order/3.png"
                      mode="aspectFit"></image>
                    <image
                      class="img"
                      v-if="item.status == 9"
                      src="/static/order/4.png"
                      mode="aspectFit"></image>
                    <text :class="['ac', item.status == 9 ? 'ac4' : '']">
                      {{ item.user_name }}
                    </text>
                  </view>
                  <view
                    :class="
                      item.status == 1 ||
                      item.status == 2 ||
                      item.status == 4 ||
                      item.status == 6
                        ? 'ac2'
                        : item.status == 8
                        ? 'ac3'
                        : 'ac4'
                    ">
                    {{ item.status_name }}
                  </view>
                </view>
              </view>
            </view>
            <w_loadmore :status="loadStatus"></w_loadmore>
          </scroll-view>
        </view>
      </template>
    </template>
    <!-- 查看报表 -->
    <template v-if="tabCurrent == 1">
      <view class="nav1 flex-between">
        <view class="flex" @click="() => (btShow = true)">
          <view class="">{{ btTitle }}</view>
          <image
            src="/static/order/d.png"
            class="d-icon"
            mode="aspectFit"></image>
        </view>
        <view class="flex" @click="exportInfo">
          <image
            src="/static/order/e.png"
            mode="aspectFit"
            class="e-icon"></image>
          <view class="nav1-text">导出</view>
        </view>
      </view>
      <view class="time-box">
        <view class="flex" @click="() => (showTime = true)">
          <view class="">选择时间</view>
          <image
            src="/static/order/d.png"
            mode="aspectFit"
            class="d1-icon"></image>
        </view>
        <view class="time-box-text">{{ showDateTitle }}</view>
      </view>
      <view class="flex1 over wrap1" style="padding-bottom: 50upx">
        <view class="">表单提交次数</view>
        <view class="wrap1-num">{{ total }}</view>
        <view class="wrap1-des">{{ btTitle }}</view>
        <view class="">
          <zb-table
            :show-header="true"
            :columns="column"
            :border="true"
            :cell-style="cellStyle"
            :cell-header-style="cellHeaderStyle"
            :flt="true"
            :data="tableData"></zb-table>
        </view>
        <view class="page-set">
          <uni-pagination
            title="标题文字"
            :current="page"
            @change="pageBtn"
            :total="total"></uni-pagination>
        </view>
      </view>

      <!-- 选择时间的弹框 -->
      <pop_timeVue
        :showTime="showTime"
        :mode="mode"
        @tiemCheck="tiemCheck"
        @confirmDate="confirmDate"
        @closeTime="() => (showTime = false)" />
      <!-- <u-popup :show="showTime">
        <view class="popup-wrap">
          <view class="pop-header" @click="() => (showTime = false)">
            <image src="/static/order/close.png" mode="aspectFit"></image>
            <text>选择时间</text>
          </view>
          <view class="popup-box flex-between">
            <view
              :class="timeIndex == index ? 'time-ac' : ''"
              @click="tiemCheck(index)"
              v-for="(item, index) in showTimeList"
              :key="index">
              {{ item }}
            </view>
          </view>
        </view>
      </u-popup> -->
      <!-- 日历弹框 -->
      <!-- <u-calendar
        :show="showDate"
        color="#DA4334"
        :mode="mode"
        @confirm="confirm"></u-calendar> -->
    </template>

    <!-- 车牌号键盘 -->
    <u-keyboard
      ref="uKeyboard"
      @change="valChange"
      @backspace="backspace"
      mode="car"
      confirmColor="#DA4334"
      @confirm="() => (showCar = false)"
      @cancel="() => (showCar = false)"
      :show="showCar"></u-keyboard>
    <!-- 时间选择弹框 -->
    <u-datetime-picker
      :show="showTime1"
      v-model="timeVal"
      :title="showTimeTitle"
      cancelColor="#DA4334"
      confirmColor="#DA4334"
      @confirm="timeBtn"
      @cancel="() => (showTime1 = false)"
      mode="time"></u-datetime-picker>
    <!-- 第一个点击弹框 -->
    <pop_navVue
      :show="btShow"
      :btList="btList"
      @popShowBtn="popShowBtn"
      @closeBtn="() => (btShow = false)" />
    <u-calendar
      :show="showDate"
      color="#DA4334"
      :maxDate="maxDate"
      :minDate="minDate"
      :default-date="defaultDate"
      :month-num="12"
      @close="() => (showDate = false)"
      @confirm="confirmDate1"></u-calendar>
    <!-- 中间商 -->
    <u-picker
      @cancel="() => (showPop1 = false)"
      @confirm="confirmPicker"
      :show="showPop1"
      confirmColor="#DA4334"
      :columns="farmerList"
      keyName="title"></u-picker>
    <u-picker
      @cancel="() => (showPop2 = false)"
      @confirm="confirmPicker2"
      :show="showPop2"
      confirmColor="#DA4334"
      :columns="farmerList2"
      keyName="title"></u-picker>
  </view>
</template>

<script>
const d = new Date();
const year = d.getFullYear();
let month = d.getMonth() + 1;
month = month < 10 ? `0${month}` : month;
const date = d.getDate() < 10 ? `0${d.getDate()}` : d.getDate();
const maxDate = new Date(year + 1, 0, 0).getTime();
const minDate = new Date(year, 0, 1).getTime();
const defaultDate = [`${year}-${month}-${date}`];
const defaultDate1 = [`${year}-${month}-${date}`];
const monthNum = (year - 2022 + 1) * 12;
import utils from "../../../plugin/util.js";
import pop_timeVue from "../../../components/order/pop_time.vue";
import pop_navVue from "../../../components/order/pop_nav.vue";
import record_status_userVue from "../../../components/order/record_status_user.vue";
import w_loadmoreVue from "../../../components/w_loadmore/w_loadmore.vue";
export default {
  components: {
    record_status_userVue,
    pop_navVue,
    pop_timeVue,
    w_loadmoreVue,
  },
  data() {
    return {
      monthNum,
      maxDate,
      minDate,
      defaultDate,
      showTimeTitle: "",
      dateIndex: 0,
      showTime1: false,
      timeVal: "",
      showCar: false,
      mark: "",
      tabCurrent: 0,
      tabList: [
        { title: "发起提交", value: 0 },
        { title: "查看报表", value: 1 },
        { title: "查看数据", value: 2 },
      ],
      navIndex: 1,
      column: [],
      tableData: [],
      showTime: false, //时间弹框
      timeIndex: 0,
      showTimeList: [
        "昨天",
        "本周",
        "本月",
        "近7天",
        "近30天",
        "近90天",
        "近180天",
        "选择时间段",
      ],
      showDate: false, //日历弹框
      mode: "range",
      orders: [],
      page: "1",
      total: 0,
      plan_date: "",
      form: {
        plan_date: "",
        num: "",
        specifications: "",
        planned_train_number: "",
        is_draft: "0",
        catch_duck_no: "",
      },
      list: [
        {
          plan_date: "",
          num: "",
          specifications: "",
          planned_train_number: "",
          is_draft: "0",
          catch_duck_no: "",
          disabled: true,
        },
      ],
      form1: {
        catch_duck_transportation_no: "",
        catch_duck_date: "",
        farmer_id: "",
        farmer_title: "",
        address: "",
        plate_number: "",
        captain_name: "",
        arrive_base_time: "",
        arrive_factory_time: "",
        production_order: "",
        specifications: "",
        is_draft: "0",
      },
      page: "1",
      btShow: false,
      btList: {
        1: "抓鸭生产计划表",
        2: "抓鸭运输数据记录表",
      },
      btTitle: "抓鸭生产计划表",
      cartVal: "",
      showTimeIndex: 0,
      showPop1: false,
      farmerList: [],
      farmerList0: [],
      farmerList1: [], //车牌号
      farmerList12: {},
      keyword: "",
      showDateTitle:
        utils.timeFormat(
          new Date(`${new Date().getFullYear()}` + "-" + "01-01")
        ) +
        "-" +
        utils.timeFormat(
          new Date(`${new Date().getFullYear()}` + "-" + "12-31")
        ),
      start_time: "",
      end_time: "",
      scrollList: [],
      mark1: "",
      mark2: "",
      isDetail: false,
      farmerList2: [],
      showPop2: false,
      saveSku: 0,
      farmerList4: ["大", "中", "小"],
      production_order: [],
      loadStatus: "loadmore",
      saveIndex: 0,
    };
  },
  created() {
    // this.getFarmer();
    this.getDetail();
    this.getDetail1();
    this.getSort();
    this.getPlanNum();
  },
  onShow() {
    //   if (uni.getStorageSync("checkAddress")) {
    //     const info = JSON.parse(uni.getStorageSync("checkAddress"));
    //     this.form1.address = info.address;
    //     console.log("地址---", this.form1.address);
    //     uni.removeStorageSync("checkAddress");
    //   }
    if (this.isDetail) {
      this.page = 1;
      this.nomore = false;
      if (this.navIndex == 1) {
        this.getBreedService();
      } else {
        this.getCatchTransport();
      }

      this.isDetail = false;
    }
    //养殖户返回，赋值
    if (uni.getStorageSync("checkAddress")) {
      const obj = JSON.parse(uni.getStorageSync("checkAddress"));
      if (this.navIndex != 1) {
        this.form1.farmer_id = obj.farmer_id;
        this.form1.farmer_title = obj.title;
        this.form1.address = obj.address;
      }
      //this.isyzh = false
      uni.removeStorageSync("checkAddress");
    }
  },
  methods: {
    addList() {
      this.list.push({
        plan_date: "",
        num: "",
        specifications: "",
        planned_train_number: "",
        catch_duck_no: "",
        disabled: false,
      });
    },
    goyzh() {
      //this.isyzh = true
      this.toRoute("/select-address?isyzh=1");
    },
    getPlanNum() {
      this.$api({
        url: "/getFleetList",
        method: "get",
        data: {},
      }).then((res) => {
        console.log(res, "车队信息");
        if (res.code === 200) {
          this.farmerList1.push(res.data.plate_number);
          this.farmerList12 = res.data;
        }
      });
    },
    cellStyle({ row, column, rowIndex, columnIndex }) {
      if (columnIndex == 0) {
        return {
          color: "#DA4334",
          fontSize: "24rpx",
        };
      }
      if (
        (Object.keys(row)[6] == "status_text" && columnIndex === 6) ||
        (Object.keys(row)[11] == "status_text" && columnIndex === 11)
      ) {
        if (row.status_text.indexOf("失败") > -1) {
          return {
            color: "#DA4334",
            fontSize: "24rpx",
          };
        }
        if (row.status_text === "已撤销") {
          return {
            color: "#8d8d8d",
            fontSize: "24rpx",
          };
        }
      }
      return {
        color: "#171717",
        fontSize: "24rpx",
      };
    },
    cellHeaderStyle() {
      return {
        backgroundColor: "#F6F1F1",
        color: "#707072",
        fontSize: "24rpx",
      };
    },
    //点击历史数据
    historyBtn(item) {
      this.toRoute({
        path: "section-detail",
        query: {
          id: item.pid,
          type: item.type, //1--放苗 2--养殖
        },
      });
    },
    //放苗
    getDetail() {
      this.$api({
        url: "/get_catch_production_log_detail",
        method: "get",
        data: {
          type: "1",
        },
      }).then((res) => {
        if (res.code === 200 && Object.keys(res.data).length > 0) {
          this.form = res.data;
          this.mark1 = res.data.info || "";
          this.mark = this.mark1 || "";
          // res.data.detail.forEach((item) => {
          // 	item.disabled = false;
          // });
          // res.data.detail[0].disabled = true;
          // this.list = res.data.detail;
          // this.plan_date = ''
        }
      });
    },
    //养殖
    getDetail1() {
      this.$api({
        url: "/get_catch_transport_log_detail",
        method: "get",
        data: {
          type: "1",
        },
      }).then((res) => {
        if (res.code === 200 && Object.keys(res.data).length > 0) {
          this.form1 = res.data;
          this.mark2 = res.data.info;
        }
      });
    },
    //点击数据跳转到详情页面
    goDetail(item) {
      if (item.pid > 0) {
        this.toRoute({
          path: "edit-record",
          query: {
            id: item.id,
            type: this.navIndex + 2, //1--放苗 2--养殖
            pid: true,
          },
        });
      } else {
        this.toRoute({
          path: "section-detail",
          query: {
            id: item.id,
            type: this.navIndex + 2, //1--放苗 2--养殖
          },
        });
      }
      this.isDetail = true;
    },
    goAddress() {
      this.toRoute("/select-address");
    },
    searchBtn() {
      this.page = 1;
      this.nomore = false;
      if (this.navIndex == 1) {
        this.getBreedService();
      } else {
        this.getCatchTransport();
      }
    },
    loadingMore() {
      if (this.nomore) return;
      this.page++;
      if (this.navIndex == 1) {
        this.getBreedService(true);
      } else {
        this.getCatchTransport(true);
      }
    },
    //获取养殖户列表
    getFarmer() {
      this.$api({
        url: "/farmer_list",
        method: "get",
      }).then((res) => {
        if (res.code == 200) {
          this.farmerList0.push(res.data);
        }
      });
    },
    confirmPicker(e) {
      console.log(e, "养殖户。中阿金是");
      if (this.saveIndex == 0) {
        this.form1.farmer_id = e.value[0].farmer_id;
        this.form1.farmer_title = e.value[0].title;
        this.form1.address = e.value[0].address;
      } else {
        this.form1.plate_number = e.value[0].title;
        this.form1.captain_name = this.farmerList12.captain_name.filter(
          (item) => item.title == e.value[0].title
        )[0].value;
      }
      this.showPop1 = false;
    },
    showPop(k) {
      this.showPop1 = true;
      this.saveIndex = k;
      this.farmerList = this["farmerList" + k];
    },
    confirmPicker2(e) {
      if (this.saveSku == 0) {
        this.form1.production_order = e.value[0];
      } else {
        this.form1.specifications = e.value[0];
      }
      this.showPop2 = false;
    },
    //获取当天存在的
    getSort() {
      this.$api({
        url: "/getproductionOrder",
        method: "get",
        data: {},
      }).then((res) => {
        if (res.code === 200) {
          this.production_order = res.data.production_order;
        }
      });
    },
    showSku(k) {
      this.saveSku = k;
      this.farmerList2 = [];
      this.showPop2 = true;
      if (k == 0) {
        const targetSet = new Set(this.production_order);
        const missingNumbers = Array.from(
          { length: 100 },
          (_, i) => i + 1
        ).filter((num) => !targetSet.has(num));
        this.farmerList2.push(missingNumbers);
      } else {
        this.farmerList2.push(this.farmerList4);
      }
    },
    showTimeBtn(k) {
      this.showTime1 = true;
      this.showTimeIndex = k;
      this.showTimeTitle = k == 0 ? "到达基地时间" : "到达工厂时间";
    },
    showDateBtn(k) {
      this.dateIndex = k;
      this.showDate = true;

      if (this.navIndex == 1) {
        this.defaultDate = this.getNextDayByTimestamp(new Date());
      } else {
        this.defaultDate = defaultDate1;
      }
    },
    confirmDate1(e, k) {
      if (this.dateIndex == 1) {
        this.form1.catch_duck_date = e[0];
      } else {
        this.plan_date = e[0];
      }
      this.showDate = false;
    },
    //第一个弹框事件
    popShowBtn(k) {
      this.btShow = false;
      this.page = 1;
      this.navIndex = k;
      this.btTitle = this.btList[k];
      if (k == 1) {
        this.getBreedService();
      } else {
        this.getCatchTransport();
      }
    },
    //运输
    getCatchTransport(flg = false) {
      const page = flg ? this.page : (this.page = 1);
      const type = this.timeIndex == null ? "" : this.timeIndex + 1;
      this.$api({
        url: "/get_catch_transport_log_list",
        method: "get",
        data: {
          page: this.page,
          limit: "10",
          type,
          keyword: this.keyword,
          start_time: this.start_time,
          end_time: this.end_time,
          option_type: this.tabCurrent == 1 ? "1" : "",
        },
      }).then((res) => {
        if (res.code === 200) {
          this.total = res.data.total;
          if (this.tabCurrent == 1) {
            this.tableData = res.data.list;
            this.showTime = false;
            this.column = [
              {
                name: "catch_duck_transportation_no",
                label: "序号",
                fixed: true,
                width: 120,
                align: "center",
                emptyString: "--",
              },
              {
                name: "catch_duck_date",
                label: "抓鸭日期",
                sorter: false,
                align: "center",
              },
              {
                name: "farmer_title",
                label: "养殖户",
                align: "center",
              },
              { name: "address", label: "地址", align: "center" },
              {
                name: "plate_number",
                label: "车牌号",
                align: "center",
              },
              {
                name: "captain_name",
                label: "队长姓名",
                align: "center",
              },
              {
                name: "arrive_base_time",
                label: "到达基地时间",
                align: "center",
              },
              {
                name: "arrive_factory_time",
                label: "到达工厂时间",
                align: "center",
              },
              {
                name: "production_order",
                label: "生产排序",
                align: "center",
              },
              {
                name: "specifications",
                label: "鸭规格",
                align: "center",
              },
              { name: "info", label: "备注", align: "center" },
              {
                name: "status_text",
                label: "审核状态",
                sorter: false,
                align: "center",
              },
            ];
          } else {
            if (flg) {
              this.scrollList = this.scrollList.concat(res.data.list);
            } else {
              this.scrollList = res.data.list;
            }
            this.nomore =
              res.data.total / this.limit > this.page ? false : true;
            this.loadStatus = this.nomore ? "nomore" : "loading";
          }
        }
      });
    },
    exportInfo() {
      let obj = {
        type: this.timeIndex == null ? "" : this.timeIndex + 1,
        start_time: this.start_time,
        end_time: this.end_time,
        form_type: this.navIndex + 2,
      };
      this.$store.dispatch("exportInfo", obj);
    },
    //抓鸭
    getBreedService(flg = false) {
      const page = flg ? this.page : (this.page = 1);
      const type = this.timeIndex == null ? "" : this.timeIndex + 1;
      this.$api({
        url: "/get_catch_production_log_list",
        method: "get",
        data: {
          page,
          limit: "10",
          type,
          keyword: this.keyword,
          start_time: this.start_time,
          end_time: this.end_time,
          option_type: this.tabCurrent == 1 ? "1" : "",
        },
      }).then((res) => {
        if (res.code === 200) {
          this.total = res.data.total;
          if (this.tabCurrent == 1) {
            this.tableData = res.data.list;
            this.showTime = false;
            this.column = [
              {
                name: "catch_duck_no",
                label: "序号",
                fixed: true,
                width: 80,
                align: "center",
                emptyString: "--",
              },
              {
                name: "plan_date",
                label: "计划生产日期",
                sorter: false,
                align: "center",
              },
              {
                name: "num",
                label: "只数",
                align: "center",
              },
              {
                name: "specifications",
                label: "规格",
                align: "center",
              },
              {
                name: "planned_train_number",
                label: "计划车次",
                align: "center",
              },
              { name: "info", label: "备注", align: "center" },
              {
                name: "status_text",
                label: "审核状态",
                sorter: false,
                align: "center",
              },
            ];
          } else {
            if (flg) {
              this.scrollList = this.scrollList.concat(res.data.list);
            } else {
              this.scrollList = res.data.list;
            }
            this.nomore =
              res.data.total / this.limit > this.page ? false : true;
            this.loadStatus = this.nomore ? "nomore" : "loading";
          }
        }
      });
    },
    checkObj(obj, k) {
      // 遍历对象中的每个字段
      for (let key in obj) {
        // 跳过production_section_four_product_no字段
        // console.log(k, "k--------", key);
        if (k.includes(key) && !obj[key]) {
          return false;
        }
      }
      return true;
    },
    //tab- 0 -提交
    submitBtn(k) {
      if (this.navIndex == 1) {
        const is_draft = k == 0 ? "1" : "0";
        this.getProduction(is_draft);
      } else {
        this.form1.is_draft = k == 0 ? "1" : "0";
        this.getTransport();
      }
    },
    getNextDayByTimestamp(date) {
      const timestamp = date.getTime() + 24 * 60 * 60 * 1000;
      return new Date(timestamp).toLocaleDateString().replace(/\//g, "-");
    },
    //抓鸭生产
    getProduction(is_draft = "0") {
      console.log(this.list);

      if (!this.plan_date) {
        this.plan_date = this.getNextDayByTimestamp(new Date());
      }
      // if (is_draft != 1) {
      //   const arr = ["plan_date", "num"];
      //   const s = this.checkObj(this.form, arr);
      //   if (!s) {
      //     uni.showToast({
      //       title: "请输入",
      //       icon: "none",
      //     });
      //     return;
      //   }
      // }

      this.$api({
        url: "/save_catch_production_log",
        method: "post",
        data: {
          is_draft,
          plan_date: this.plan_date,
          details: JSON.stringify(this.list),
          info: this.mark,
        },
      }).then((res) => {
        uni.showToast({
          title: res.msg,
          icon: "none",
        });
        if (res.code === 200 && is_draft != 1) {
          // Object.keys(this.form).forEach((key) => (this.form[key] = ""));
          this.list.forEach((item) => {
            Object.keys(item).forEach((v) => (item[v] = ""));
          });
          this.plan_date = "";
        }
      });
    },
    //抓鸭运输保存
    getTransport() {
      if (!this.form1.catch_duck_date) {
        this.form1.catch_duck_date = new Date()
          .toLocaleDateString()
          .replace(/\//g, "-");
      }
      if (this.form1.is_draft != 1) {
        const arr = [
          "catch_duck_date",
          "farmer_title",
          "plate_number",
          "production_order",
        ];
        const s = this.checkObj(this.form1, arr);
        if (!s) {
          uni.showToast({
            title: "请输入",
            icon: "none",
          });
          return;
        }
      }
      this.$api({
        url: "/save_catch_transport_log",
        method: "post",
        data: {
          ...this.form1,
          info: this.mark,
        },
      }).then((res) => {
        uni.showToast({
          title: res.msg,
          icon: "none",
        });
        if (res.code === 200 && this.form1.is_draft != 1) {
          Object.keys(this.form1).forEach((key) => (this.form1[key] = ""));
        }
      });
    },
    // 按键被点击(点击退格键不会触发此事件)
    valChange(val) {
      // 将每次按键的值拼接到value变量中，注意+=写法
      this.form1.plate_number += val;
      console.log(this.form1.plate_number);
    },
    // 退格键被点击
    backspace() {
      // 删除value的最后一个字符
      if (this.form1.plate_number.length)
        this.form1.plate_number = this.form1.plate_number.substr(
          0,
          this.form1.plate_number.length - 1
        );
      console.log(this.form1.plate_number);
    },

    //时间弹框
    timeBtn(e) {
      console.log("到达基地时间", e.value);
      if (this.showTimeIndex == 0) {
        this.form1.arrive_base_time = e.value;
      } else {
        this.form1.arrive_factory_time = e.value;
      }
      this.showTime1 = false;
    },
    tabClick(e) {
      console.log("点击tab", e);
      this.tabCurrent = e.value;
      this.navIndex = 1;
      this.timeIndex = null;
      this.btTitle = "抓鸭生产计划表";
      if (this.tabCurrent != 0) {
        this.page = 1;
        this.nomore = false;
        this.loadStatus = "loadmore";
        if (this.navIndex == 1) {
          this.getBreedService();
        } else {
          this.getCatchTransport();
        }
      }
    },
    //导航一
    navBtn(k) {
      this.navIndex = k;
      if (k == 1) {
        this.mark = this.mark1;
      } else {
        this.mark = this.mark2;
      }
      if (this.tabCurrent == 2) {
        this.page = 1;
        this.nomore = false;
        this.loadStatus = "loadmore";
        if (this.navIndex == 1) {
          this.getBreedService();
        } else {
          this.getCatchTransport();
        }
      }
    },
    confirmDate({ e, data, index }) {
      this.start_time = e[0];
      this.end_time = e[e.length - 1];
      this.timeIndex = index;
      this.showDateTitle = data;
      if (this.navIndex == 1) {
        this.getBreedService();
      } else {
        this.getCatchTransport();
      }
    },
    //查看列表的时间弹框选择
    tiemCheck({ k, data }) {
      this.timeIndex = k;
      // if (k == this.showTimeList.length - 1) {
      //   this.showDate = true;
      // }
      this.showDateTitle = data;
      if (this.navIndex == 1) {
        this.getBreedService();
      } else {
        this.getCatchTransport();
      }
    },
    //点击分页事件
    pageBtn(e) {
      console.log("分页----", e);
      this.page = e.current;
      if (this.navIndex == 1) {
        this.getBreedService(true);
      } else {
        this.getCatchTransport(true);
      }
    },
    //日历弹框
    confirm(e) {
      console.log(e);
    },
  },
};
</script>

<style lang="scss" scoped>
.transport {
  width: 100%;
  height: 100%;
  background: #f5f7f9;

  ::v-deep .u-tabs__wrapper__nav__item {
    flex: 1;
  }
  ::v-deep .u-popup {
    flex: 0 !important;
  }
  .header {
    height: 88upx;
    width: 100%;
    background: #fff;
  }
  .nav {
    padding: 20upx 0;
    & > view {
      width: 192rpx;
      height: 52rpx;
      text-align: center;
      line-height: 52upx;
      background: #ffffff;
      border-radius: 8rpx 8rpx 8rpx 8rpx;
      font-size: 24rpx;
      color: #9695a3;
      margin-right: 52upx;
    }
    .nav-ac {
      background: #da4334;
      color: #ffffff;
    }
  }
  .wrap {
    background: #fff;
    padding: 0 32upx;
    .box {
      padding: 28upx 0;
      font-size: 32rpx;
      border-bottom: 1rpx solid #e4e4e4;
      & > view {
        font-size: 32rpx;
        color: #161616;
      }
      & > input {
        height: 28upx;
        font-size: 32rpx;
        margin-top: 28upx;
      }

      .box-b {
        margin-top: 28upx;
        & > input {
          height: 28upx;
          font-size: 32rpx;
        }
        & > image {
          width: 12upx;
          height: 21upx;
        }
      }
      ::-webkit-input-placeholder {
        color: #a0a0a0;
      }
    }

    .l-wrap {
      padding: 58upx 8upx 30upx 54upx;
      .l-box {
        position: relative;
        margin-bottom: 38upx;
        &-c {
          position: absolute;
          top: 0;
          left: -32upx;
          width: 16rpx;
          height: 16rpx;
          background: #d7d7d7;
          border-radius: 50%;
        }
        &-line {
          position: absolute;
          top: 28upx;
          left: -25upx;
          width: 2upx;
          height: 100upx;
          background: #d7d7d7;
        }
        &-title {
          font-size: 24rpx;
          color: #a0a0a0;
          & > view:nth-of-type(1) {
            font-size: 32rpx;
            color: #3d3d3d;
            margin-bottom: 12upx;
          }
        }
        &-r {
          &-t {
            font-size: 24rpx;
            color: #a0a0a0;
            & > image {
              width: 68rpx;
              height: 68rpx;
              margin-bottom: 8upx;
            }
          }
          .arrow {
            width: 32upx;
            height: 32upx;
            margin-left: 10upx;
            margin-right: 10upx;
            margin-top: 18upx;
          }
          &-add {
            width: 68rpx;
            height: 68rpx;
            background: #ffffff;
            border-radius: 12rpx 12rpx 12rpx 12rpx;
            border: 2rpx solid #ededed;
            & > image {
              width: 36upx;
              height: 36upx;
            }
          }
        }
      }
    }
  }
  .footer {
    background: #fff;
    padding: 8upx 32upx;

    padding-bottom: env(safe-area-inset-bottom);
    .box-icon {
      font-size: 24rpx;
      color: #000000;
      & > image {
        width: 39upx;
        height: 38upx;
        margin-bottom: 10upx;
      }
    }
    .btn {
      width: 580rpx;
      height: 80rpx;
      background: #da4334;
      border-radius: 422rpx 422rpx 422rpx 422rpx;
      border: 1rpx solid #dafbff;
      font-weight: 500;
      font-size: 28rpx;
      color: #ffffff;
      text-align: center;
      line-height: 80upx;
    }
  }
  .nav1 {
    height: 88rpx;
    background: #ffffff;
    font-size: 32rpx;
    color: #161616;
    box-sizing: border-box;
    padding: 0 32upx;
    .d-icon {
      width: 20rpx;
      height: 13rpx;
      margin-left: 18upx;
    }
    &-text {
      font-size: 28rpx;
      color: #da4334;
      margin-left: 6upx;
    }
    .e-icon {
      width: 28rpx;
      height: 28rpx;
    }
  }
  .time-box {
    padding: 30upx 32upx 16upx;
    font-size: 28rpx;
    color: #1c2127;
    .d1-icon {
      width: 12upx;
      height: 12upx;
      margin-left: 4upx;
    }
    &-text {
      font-size: 24rpx;
      color: #6f6e74;
      margin-top: 48upx;
    }
  }

  .wrap1 {
    background: #fff;
    padding: 28upx 32upx;
    font-size: 28rpx;
    color: #171717;
    &-num {
      font-size: 48rpx;
      padding: 48upx 0;
      border-bottom: 1rpx solid #e4e4e4;
    }
    &-des {
      font-size: 28rpx;
      color: #161616;
      margin: 28upx 0 24upx;
    }
  }
  .popup-wrap {
    padding: 34upx 32upx 0;
    width: 100%;
    box-sizing: border-box;
    .pop-header {
      position: relative;
      font-weight: bold;
      text-align: center;
      font-size: 28rpx;
      color: #181818;
      margin-bottom: 50upx;
      & > image {
        position: absolute;
        width: 32upx;
        height: 32upx;
        left: 30upx;
        top: 50%;
        transform: translateY(-50%);
      }
    }
    .popup-box {
      flex-wrap: wrap;
      margin-bottom: 200upx;
      & > view {
        width: 320rpx;
        height: 76rpx;
        background: #ffffff;
        border-radius: 12rpx 12rpx 12rpx 12rpx;
        border: 2rpx solid #eaeaea;
        text-align: center;
        line-height: 76upx;
        font-size: 26rpx;
        color: #171717;
        margin-bottom: 20upx;
      }
      .time-ac {
        border: 2rpx solid #da4334;
        color: #da4334;
      }
    }
  }
  .search {
    width: 702rpx;
    height: 68rpx;
    background: #ffffff;
    border-radius: 12rpx 12rpx 12rpx 12rpx;
    border: 2rpx solid rgba(0, 0, 0, 0.06);
    margin: 0 auto 20upx;
    box-sizing: border-box;
    padding: 0 20upx;
    font-size: 28rpx;
    & > image {
      width: 32upx;
      height: 32upx;
      margin-right: 16upx;
    }
  }
  .content-wrap {
    padding: 0 24upx;
    .content-box {
      padding: 32upx 32upx 28upx;
      background: #fff;
      margin-bottom: 20upx;
      font-size: 24rpx;
      color: #8d8d8d;
      .t {
        font-size: 32rpx;
        color: #171717;
      }
      .t1 {
        color: #afafaf;
      }
      .edit-text {
        width: 78rpx;
        height: 36rpx;
        background: #f17303;
        font-size: 24rpx;
        color: #ffffff;
        border-radius: 14upx 0 14upx 0;
        margin-left: 16upx;
        text-align: center;
        line-height: 36upx;
      }
      .no {
        margin-top: 30upx;
        margin-bottom: 12upx;
        color: #8d8d8d;
      }
      .cred {
        font-size: 24rpx;
        color: #da4334;
      }
      .t2 {
        color: #8d8d8d;
      }
      .mb12 {
        margin-bottom: 12upx;
      }
      .ac {
        font-size: 26rpx;
        color: #8d8d8d;
      }
      .ac1 {
        font-size: 26rpx;
        color: #171717;
      }
      .img {
        width: 40upx;
        height: 40upx;
        margin-right: 8upx;
      }
      .ac2 {
        font-size: 26rpx;
        color: #f17303;
      }
      .ac3 {
        font-size: 26rpx;
        color: #0cb18e;
      }
      .ac4 {
        font-size: 26rpx;
        color: #8d8d8d;
      }
      .mt34 {
        margin-top: 34upx;
      }
    }
  }
  .page-set {
    margin: 20upx 0;
  }
  .mb16 {
    margin-bottom: 16upx;
  }
  .sc {
    color: #da4334;
  }
  .tip {
    padding: 20upx 32upx;
    font-size: 24rpx;
    color: #a0a0a0;
  }
  .del {
    font-size: 24rpx;
    color: #da4334;
  }
  .add-icon {
    padding: 22upx 0;
    & > image {
      width: 40upx;
      height: 40upx;
    }
  }
}
</style>
